package com.elong.common.util;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;

import org.apache.log4j.Logger;

/**
 * 
 * @Title:LoggerUtil.java
 * 
 * @Description:日志工具类
 * 
 * @author zhaoyang
 * @date Jan 17, 2014 10:33:20 AM
 * @version V1.0
 */
public class LoggerUtil {

    /** debugLogger */
    public static void debug(Object msg) {
        Logger.getLogger("debugLogger").debug(msg);
    }

    /** 记录本系统调用外部系统接口的Logger */
    public static void inOutInfo(String msg) {
        Logger.getLogger("inOutLogger").info(msg);
    }

    /** 缓存存取的Logger */
    public static void cacheInfo(Object msg) {
        Logger.getLogger("cacheLogger").info(msg);
    }

    /** errorLogger */
    public static void error(String msg, Exception e) {
        printError(Logger.getLogger("errorLogger"), msg, e);
    }

    public static void printError(Logger logger, String msg, Exception e) {
        if (msg != null) {
            logger.error(msg);
        }
        if (e != null) {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            e.printStackTrace(new PrintWriter(buf, true));
            logger.error(buf.toString());
        }
    }

}
